﻿using System.Diagnostics;
using LFSRecord2.Misc;

namespace LFSRecord2.Model.UserActions
{
    public class UserActionKeyFrameInterpolationChanged : UserActionBase
    {
        // Action description, so we can replay this action (and reverse it)
        public int LayerIndex { get; set; }
        public int PropertyIndex { get; set; }
        public int KeyFrameIndex { get; set; }
        public KeyFrameInterpolationTypes OldIntIn { get; set; }
        public KeyFrameInterpolationTypes NewIntIn { get; set; }
        public KeyFrameInterpolationTypes OldIntOut { get; set; }
        public KeyFrameInterpolationTypes NewIntOut { get; set; }

        public UserActionKeyFrameInterpolationChanged()
        {
            Action = UserActionTypes.KeyFrameInterpolationChanged;
        }

        public override void DoUndo()
        {
            Debug.WriteLine("Undoing a KeyFrameInterpolationChange action");
             if (KeyFrameIndex > LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames.Count - 1)
            {
                Logger.LogError("Invalid keyframe reference while undoing kfIntAction");
            }
            LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames[KeyFrameIndex].InterpolationTypeIn = OldIntIn;
            LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames[KeyFrameIndex].InterpolationTypeOut = OldIntOut;
        }

        public override void DoRedo()
        {
            Debug.WriteLine("Redoing a KeyFrameInterpolationChanged action");
            if (KeyFrameIndex > LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames.Count - 1)
            {
                Logger.LogError("Invalid keyframe reference while redoing kfIntAction");
            }
            LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames[KeyFrameIndex].InterpolationTypeIn = NewIntIn;
            LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames[KeyFrameIndex].InterpolationTypeOut = NewIntOut;
        }
    }
}
